home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / textfield.lha / Textfield / MUITest / Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-15  |  2.5 KB  |  104 lines

  1. /*
  2.  * MUI Test
  3.  *
  4.  * MUITest is a small example that shows how one would read
  5.  * the text from the Textfield gadget used in a MUI interface.
  6.  */
  7.  
  8. #include <stdio.h>
  9.  
  10. #include <exec/types.h>
  11. #include <libraries/mui.h>
  12. #include <intuition/classes.h>
  13. #include <gadgets/textfield.h>
  14.  
  15. #include <proto/muimaster.h>
  16. #include <proto/dos.h>
  17. #include <proto/exec.h>
  18. #include <proto/intuition.h>
  19.  
  20. #include <clib/alib_protos.h>
  21.  
  22. #include "muitest.h"
  23.  
  24. static BOOL init(void);
  25. static void clean(void);
  26.  
  27. struct Library *MUIMasterBase;
  28.  
  29. main()
  30. {
  31.     BOOL running = TRUE;
  32.     ULONG signal;
  33.     struct ObjApp *obj_app;
  34.  
  35.     if (init()) {
  36.         obj_app = CreateApp();
  37.         if (obj_app) {
  38.             DoMethod(obj_app->window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, obj_app->App, 2,
  39.                         MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  40.             DoMethod(obj_app->text, MUIM_Notify, TEXTFIELD_Lines, MUIV_EveryTime,
  41.                         obj_app->sbar, 3, MUIM_Set, MUIA_Prop_Entries, MUIV_TriggerValue);
  42.             DoMethod(obj_app->text, MUIM_Notify, TEXTFIELD_Visible, MUIV_EveryTime,
  43.                         obj_app->sbar, 3, MUIM_Set, MUIA_Prop_Visible, MUIV_TriggerValue);
  44.             DoMethod(obj_app->text, MUIM_Notify, TEXTFIELD_Top, MUIV_EveryTime,
  45.                         obj_app->sbar, 3, MUIM_NoNotifySet, MUIA_Prop_First, MUIV_TriggerValue);
  46.             DoMethod(obj_app->sbar, MUIM_Notify, MUIA_Prop_First, MUIV_EveryTime,
  47.                         obj_app->text, 3, MUIM_NoNotifySet, TEXTFIELD_Top, MUIV_TriggerValue);
  48.  
  49.             set(obj_app->window, MUIA_Window_Open, TRUE);
  50.  
  51.             while (running) {
  52.                 switch (DoMethod(obj_app->App, MUIM_Application_Input, &signal)) {
  53.                     case MUIV_Application_ReturnID_Quit:
  54.                         running = FALSE;
  55.                         break;
  56.                 }
  57.                 if (running && signal) {
  58.                     Wait(signal);
  59.                 }
  60.             }
  61.  
  62.             {
  63.                 struct Window *window;
  64.                 struct Gadget *gadget;
  65.                 char *text;
  66.                 ULONG size, i;
  67.  
  68.                 GetAttr(MUIA_Window_Window, obj_app->window, (ULONG *)&window);
  69.                 GetAttr(MUIA_Boopsi_Object, obj_app->text, (ULONG *)&gadget);
  70.                 if (window) {
  71.                     SetGadgetAttrs(gadget, window, NULL, TEXTFIELD_ReadOnly, TRUE, TAG_DONE);
  72.                     GetAttr(TEXTFIELD_Size, gadget, &size);
  73.                     GetAttr(TEXTFIELD_Text, gadget, (ULONG *)&text);
  74.                     if (text && size) {
  75.                         for (i = 0; i < size; i++) {
  76.                             putchar(text[i]);
  77.                         }
  78.                     }
  79.                     SetGadgetAttrs(gadget, window, NULL, TEXTFIELD_ReadOnly, FALSE, TAG_DONE);
  80.                 } else {
  81.                     printf("No window\n");
  82.                 }
  83.             }
  84.  
  85.             DisposeApp(obj_app);
  86.         }
  87.     }
  88. }
  89.  
  90. static BOOL init(void)
  91. {
  92.     MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN);
  93.     if (MUIMasterBase) {
  94.         return TRUE;
  95.     } else {
  96.         return FALSE;
  97.     }
  98. }
  99.  
  100. static void clean(void)
  101. {
  102.     CloseLibrary(MUIMasterBase);
  103. }
  104.